package calculator;

import java.util.ArrayList;
import java.util.HashMap;

import bean.Table;

public class DynamicStorer {
	private HashMap<String, Integer> warehouse = new HashMap<String, Integer>();
	private static final ArrayList<Integer> INTEGER_LIST = new ArrayList<Integer>(14);

	public DynamicStorer(){
		for (int i=0;i<= 13;i++){
			Integer a = Integer.valueOf(i);
			INTEGER_LIST.add(a);
		}
	}
	
	
	public void storeTableResult(Table t, int nsTricks) {
		if (t == null || t.getHands() == null)
			return;

		warehouse.put(t.toEncode(), INTEGER_LIST.get(nsTricks));
	}

	/**
	 * return null if no record found
	 * 
	 * @param t
	 * @return
	 */
	public Short getResult(Table t) {
		if (t == null || t.getHands() == null)
			return null;
		Integer result = warehouse.get(t.toEncode());
		if (result == null)
			return null;
		else
			return result.shortValue();

	}

	public int getSize() {
		return warehouse.size();
	}
}
